package com.chenshang.service.intl;

import java.util.Map;

import com.chenshang.config.Environment;
import com.chenshang.service.base.HttpService;
import com.chenshang.util.JaxbUtil;
import com.travelzen.flight.base.TzRequest;
import com.travelzen.flight.international.FlightSearchResponse;

public class FlightSearch {

	public static String flightSearch(Environment environment, Boolean isDomestic, TzRequest tzRequest, Map<String, Object> result) {

		HttpService httpService = new HttpService();
		String flightSearchRequest = JaxbUtil.convertToXml(tzRequest);
		String flightSearchResponse = "";
		if (isDomestic) {
			flightSearchResponse = httpService.sendPostHttpRequest(environment.getValue() + Environment.domestic.getValue(), flightSearchRequest);
		}
		flightSearchResponse = httpService.sendPostHttpRequest(environment.getValue() + Environment.international.getValue(), flightSearchRequest);

		FlightSearchResponse searchResponse = (FlightSearchResponse) JaxbUtil.convertToTzResponseByXml(flightSearchResponse).getResponseEntity();

		result.put("tzResponse", searchResponse.getFlightSegmentResult());

		return flightSearchResponse;
	}
}
